<template>
  <div class="app-container">
    <!--地图div-->
    <div style="position:absolute;top:0px;left:0px;width:100%;height:100%;">
      <HouseMap
          :queryMapBool="queryMapBool"
          :mapExtent="mapExtent"
          @showQueryMapDraw="showQueryMapDraw"
      ></HouseMap>
    </div>
    <!--index页面div-->
    <div id="houseMapDiv" class="ol-popup">
        <el-button type="primary" @click="handleAssess" style="margin:20px 20px 20px 48px;">评估</el-button>
        <el-button type="primary" @click="handleAnalyze" style="float: right; margin:20px;">评估结果分析</el-button><br>
        <el-button type="primary" @click="handleResult" style="margin-left:20px;">结果查看</el-button>
        <!-- 结果查看 -->
        <div class="showResult" v-if="openResult">
              <el-radio-group v-model="radioResult" @change="radioResultChange">
                <el-radio label="1">房屋破坏评估结果</el-radio>
                <el-radio label="0">房屋抗震能力评估结果</el-radio>
              </el-radio-group>
        </div>
        <div class="showResultList" v-if="radioResult">
            <el-table :data="resultList" height="400">
                <el-table-column label="编号" align="center" prop="number" />
                <el-table-column label="业务人员" align="center" prop="people" />
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template #default="scope">
                        <el-button type="text" @click="handleExport(scope.row.id)" v-if="radioResult&&radioResult=='1'">下载</el-button>
                        <el-button type="text" @click="handleExport1(scope.row.id)" v-if="radioResult&&radioResult=='0'">下载</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- <pagination v-show="total > 0" :total="total" v-model:page="formData.page" v-model:limit="formData.rows"
            @pagination="getAnalyze" /> -->
        </div>
        <div class="showAssess" v-if="openAssess">
            <p>评估内容</p>
            <el-radio-group v-model="content" @change="changeRadio">
                <el-radio label="房屋抗震能力评估">房屋抗震能力评估</el-radio>
                <el-radio label="房屋破坏评估">房屋破坏评估</el-radio>
            </el-radio-group>
             <p>设定评估范围
                <el-radio-group v-model="view" style="margin-left:20px">
                    <el-radio label="手动选择">手动选择</el-radio>
                    <!--zyt修改-->
                    <!--<el-radio label="地图圈选">地图圈选</el-radio>-->
                </el-radio-group>
            </p>
            <template v-if="view=='手动选择'">
                <template v-if="type == 1">
                    <el-cascader ref="departmentTree" :options="options" :props="props" collapse-tags clearable
                        collapse-tags-tooltip @change="departmentChange" />
                </template>
                <template v-else-if="type == 2">
                    <el-cascader ref="departmentTree" :options="options1" :props="props1" collapse-tags clearable
                        collapse-tags-tooltip @change="departmentChange" />
                </template>
            </template>
            <template v-else></template>
            <div class="footer">
                <el-button type="primary" @click="openAssess = false">取消</el-button>
                <el-button type="primary" @click="setParameter(0)" :disabled="selectValue.length == 0">设定参数</el-button>
                <el-button type="primary" @click="setParameter(1)" :disabled="selectValue.length == 0" v-if="content!='房屋破坏评估'">格网参数设定</el-button>
            </div>
        </div>
        <el-dialog v-model="openParameter" append-to-body width="650px" :title="num == 0?'设定参数':'格网参数设定'">
            <p></p>
            <el-form ref="assessRef" :model="queryParams" :rules="rules" label-width="80px">
                <el-row>
                    <template v-if="num==1">
                        <el-col>
                            <el-form-item label="地震烈度" prop="lieDu">
                                <el-radio-group v-model="queryParams.lieDu">
                                    <el-radio label="6">VI度</el-radio>
                                    <el-radio label="7">VII度</el-radio>
                                    <el-radio label="8">VIII度</el-radio>
                                    <el-radio label="9">IX度</el-radio>
                                    <el-radio label="10">X度</el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
                        <el-col>
                            <el-form-item label="数据使用说明">
                                <span>使用评估范围内地震灾害损失评估系统维护的人口经济建筑物公里格网、建筑物易损性数据、人口和建筑物概况。</span><br>
                                <span>如无此数据，需到地震灾害损失预评估系统内维护。</span>
                            </el-form-item>
                        </el-col>
                    </template>
                    <template v-if="num==0">
                        <el-col :span="20">
                        <el-form-item label="地震烈度" prop="lieDu">
                            <el-radio-group v-model="queryParams.lieDu">
                                <el-radio label="VI">VI度</el-radio>
                                <el-radio label="VII">VII度</el-radio>
                                <el-radio label="VIII">VIII度</el-radio>
                                <el-radio label="IX">IX度</el-radio>
                                <el-radio label="X">X度</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <p style="color:red;margin: 7px 0;cursor: pointer;" @click="handleExplain" v-if="num==0">公式说明</p>
                    </el-col>
                    <el-col>
                        <el-form-item label="城镇住宅" prop="czzzDataVersion" label-width="150px">
                            <SelectVersion v-model="queryParams.czzzDataVersion" title="城镇住宅" :list="selectValueId" num="czzz" name="czzzDataVersion" @getSelecVersion="getSelecVersion" />
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="城镇非住宅" prop="czfzzDataVersion" label-width="150px">
                            <SelectVersion v-model="queryParams.czfzzDataVersion" title="城镇非住宅" :list="selectValueId" num="czfzz" name="czfzzDataVersion"  @getSelecVersion="getSelecVersion"></SelectVersion>
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="农村住宅(独立住宅)" prop="nczzdlzzDataVersion" label-width="150px">
                            <SelectVersion v-model="queryParams.nczzdlzzDataVersion" title="农村住宅(独立住宅)" :list="selectValueId" num="nczzdlzz" name="nczzdlzzDataVersion"  @getSelecVersion="getSelecVersion"></SelectVersion>
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="农村住宅(集合住宅)" prop="nczzjtzzDataVersion" label-width="150px">
                            <SelectVersion v-model="queryParams.nczzjtzzDataVersion" title="农村住宅(集合住宅)" :list="selectValueId" num="nczzjhzz" name="nczzjtzzDataVersion"  @getSelecVersion="getSelecVersion"></SelectVersion>
                        </el-form-item>
                    </el-col>
                    <el-col>
                        <el-form-item label="农村非住宅" prop="ncfzzDataVersion" label-width="150px">
                            <SelectVersion v-model="queryParams.ncfzzDataVersion" title="农村非住宅" :list="selectValueId" num="ncfzz" name="ncfzzDataVersion"  @getSelecVersion="getSelecVersion"></SelectVersion>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="建筑物易损性矩阵">
                            <el-table stripe :data="selectValue" style="width: 100%;">
                                <el-table-column prop="province" align="center" label="省" show-overflow-tooltip />
                                <el-table-column prop="city" align="center" label="市" show-overflow-tooltip />
                                <el-table-column prop="prefecture" align="center" label="区县" show-overflow-tooltip />
                                <el-table-column label="建筑物易损性矩阵" align="center" class-name="small-padding fixed-width"
                                    width="200">
                                    <template #default="scope">
                                        <el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form-item>
                    </el-col>
                </template>
                    <!-- <el-col :span="12">
                        <el-form-item label="图件模板" prop="tjmb">
                            <el-select v-model="queryParams.tjmb" style="width:100%" placeholder="请选择">
                                <template v-if="content == '房屋抗震能力评估'">
                                    <el-option v-for="item in option1" :key="item.id" :label="item.name"
                                        :value="item.id">
                                    </el-option>
                                </template>
                                <template v-else>
                                    <el-option v-for="item in option2" :key="item.id" :label="item.name"
                                        :value="item.id">
                                    </el-option>
                                </template>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"></el-col>
                    <el-col :span="12">
                        <el-form-item label="制图单位" prop="ztdw">
                            <el-input v-model="queryParams.ztdw" placeholder="请输入制图单位" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"></el-col>
                    <el-col :span="12">
                      <el-form-item label="图件标题" prop="tjbt">
                          <el-input v-model="queryParams.tjbt" placeholder="请输入图件标题" />
                      </el-form-item>
                    </el-col> -->
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="openParameter = false">退出</el-button>
                    <el-button type="primary" @click="toAssess">评估</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="结果查看" v-if="openView" v-model="openView"  width="650px" append-to-body>
            <el-form ref="viewRef" label-width="130px" :model="form1" :rules="rules">
                <el-row style="margin: 20px 0;">
                    <el-col :span="24" v-if="content == '房屋抗震能力评估'">
                        <el-form-item label="房屋抗震能力">
                            <el-table stripe :data="form1.list" style="width: 100%;">
                                <el-table-column prop="province" align="center" label="省" show-overflow-tooltip />
                                <el-table-column prop="city" align="center" label="市" show-overflow-tooltip />
                                <el-table-column prop="prefecture" align="center" label="区县" show-overflow-tooltip />
                                <el-table-column prop="res" align="center" label="计算值" show-overflow-tooltip />
                                <!-- <el-table-column prop="corrected" align="center" label="修正值">
                                    <template #default="scope">
                                        <el-input type="text"></el-input>
                                    </template>
                                </el-table-column> -->
                            </el-table>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24" v-else>
                        <el-form-item label="评估结果" prop="pgjg">
                            <span style="color: #107ce5;cursor: pointer;" @click="handleExport">导出至本地</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="图件模板" prop="tjmb">
                            <el-select v-model="form1.tjmb" style="width:100%" placeholder="请选择">
                                <template v-if="content == '房屋抗震能力评估'">
                                    <el-option v-for="item in option1" :key="item.id" :label="item.name"
                                        :value="item.id">
                                    </el-option>
                                </template>
                                <template v-else>
                                    <el-option v-for="item in option2" :key="item.id" :label="item.name"
                                        :value="item.id">
                                    </el-option>
                                </template>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"></el-col>
                    <el-col :span="12">
                        <el-form-item label="制图单位" prop="ztdw">
                            <el-input v-model="form1.ztdw" placeholder="请输入制图单位" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"></el-col>
                    <el-col :span="12">
                      <el-form-item label="图件标题" prop="tjbt">
                          <el-input v-model="form1.tjbt" placeholder="请输入图件标题" />
                      </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="openView = false">退 出</el-button>
                    <el-button type="primary" @click="onlySave">仅保存结果</el-button>
                    <el-button type="primary" @click="savePic">保存&出图</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="结果查看" v-if="openPic" v-model="openPic" width="650px" append-to-body>
            <el-form ref="picRef" label-width="120px" :model="form" :rules="rules">
                <el-row style="margin: 20px 0;">
                    <el-col style="margin-bottom: 10px;">
                        <ImagePreview :src="`/attachment/downLoad?attachId=${form.attach.attachId}`"></ImagePreview>
                        <!-- <img :src="baseUrl + form.attach.attachId" :alt="baseUrl + form.attach.attachId"
                            style="width:100%" /> -->
                    </el-col>
                    <el-col v-if="steps != 2">
                        <el-form-item label="标题" prop="title">
                            <el-input v-model="form.title" placeholder="请输入标题" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="steps == 3">
                        <el-form-item label="图件模板" prop="tjmb">
                            <el-select v-model="form.tjmb" style="width:100%" placeholder="请选择">
                                <template v-if="content == '房屋抗震能力评估'">
                                    <el-option v-for="item in option1" :key="item.id" :label="item.name"
                                        :value="item.id">
                                    </el-option>
                                </template>
                                <template v-else>
                                    <el-option v-for="item in option2" :key="item.id" :label="item.name"
                                        :value="item.id">
                                    </el-option>
                                </template>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"></el-col>
                    <el-col>
                        <el-radio-group v-model="steps">
                            <el-radio :label="1">保存结果</el-radio>
                            <el-radio :label="2">重新设定参数</el-radio>
                            <el-radio :label="3">更换图件模板</el-radio>
                        </el-radio-group>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="saves">确 定</el-button>
                    <el-button @click="openPic = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog v-model="openExplain" width="650px" :title="content + '模型'" append-to-body>
            <p></p>
            <el-row>
                <el-col class="tab-title">{{ content }}模型</el-col>
                <el-col v-if="content == '房屋抗震能力评估'">
                    <span
                        class="indent">支持利用房屋的基础信息进行地震灾害风险的分析，分析采用公式，输入参数（如结构类型、破坏程度等），可得出房屋抗震能力，计算区域内的抗震能力。</span><br />
                    <span class="indent">针对某一区域进行计算时，获得该区域下房屋的建筑类型和面积；利用不同破坏程度、不同破坏烈度的估算方法，即在某区域、地震烈度为I时：</span>
                </el-col>
                <el-col v-else>
                    <span class="indent">建筑物单体在地震烈度为I下进行计算时，根据设防烈度，取五类破坏状态下最大易损性数值，根据取值生成房屋破坏分布图。</span><br />
                    <span class="indent">地震烈度I分为VI、VII、VIII、IX、X；破坏状态分为基本完好、轻微破坏、中等破坏、严重破坏、倒塌，根据数据结果对地图进行渲染获得分布图。</span>
                </el-col>
                <el-col :offset="6">
                    <!-- <span style="font-size: 16px;font-weight: bold;font-style: normal;">D<sub>I</sub>(i，j) = <span style="font-size:35px;font-weight: 100;">∑</span><sub>i</sub>
                    <span style="font-size:40px;font-weight: normal;">[</span>—<span style="position: relative;top:-12px;left: -15px;">s<sub>i</sub></span> ∑<sub>j</sub> P [<span
                            style="position: relative;top: -15px;">D<sub>j</sub></span>—<span
                            style="position: relative;top: 12px;margin-left: -10px;">I</span>] * B<sub>s</sub>
                    </span><br /><br /> -->
                    <img style="padding:10px 0" src="@/assets/images/house.png">
                </el-col>
                <el-col>
                    <span class="indent">I --表示地震烈度；</span><br />
                    <span class="indent">D<sub>I</sub>(i，j) --表示在地震烈度为I时该区域的房屋抗震能力值；</span><br />
                    <span class="indent">S<sub>i</sub> --表示该区域内 i 类建筑面积之和；</span><br />
                    <span class="indent">R<sub>I. j</sub> --表示在地震烈度为 I 时，i 类建筑的第 j 种破坏状态下易损性数值；</span><br />
                    <span class="indent">L<sub>i. j</sub> --表示 i 类建筑在第 j 种破坏状态下抗震能力指数；</span><br />
                    <span class="indent">S --表示区域内所有房屋面积之和；</span><br />
                </el-col>
            </el-row>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="openExplain = false">退出</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="请选择" v-if="openAnalyze" v-model="openAnalyze" width="600px" append-to-body>
            <p class="mt15"></p>
            <p>请选择一次计算结果</p>
            <el-table :data="dataList" row-key="id" highlight-current-row @current-change="handleCurrentChange" height="500px">
                <el-table-column label="序号" type="index" width="55" align="center">
                </el-table-column>
                <el-table-column label="编号" align="center" prop="number" />
                <el-table-column label="业务人员" align="center" prop="people" />
                <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template #default="scope">
                        <el-button type="text" @click="handleShow(scope.row.id)">展示</el-button>
                        <el-button type="text">当前展示</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="confirmAnalyze" :disabled="JSON.stringify(selectObj)=='{}'">确 定</el-button>
                    <el-button @click="openAnalyze = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="评估结果分析及建议" v-if="openSuggestion" v-model="openSuggestion" width="1000px" append-to-body>
            <p class="mt15"></p>
            <div class="suggesBox">
                <div class="leftBox">
                    <h2 style="text-align: center;">严重破坏和毁坏风险占比统计</h2>
                    <div style="height:180px;padding: 40px;display: flex;align-items: center;justify-content: center;">
                        <Chart :numObj="numObj"></Chart>
                    </div>
                    <el-divider border-style="dashed"></el-divider>
                    <el-table :data="dataList1" row-key="sdaId" style="width: 643px">
                        <el-table-column label="序号" type="index" width="55" align="center">
                          <template #default="scope">
                            <span>{{(formData1.page - 1) * formData1.rows + scope.$index + 1}}</span>
                          </template>
                        </el-table-column>
                        <el-table-column label="建筑名称" align="center" prop="jzmc" width="180" show-overflow-tooltip/>
                        <el-table-column label="经度" align="center" prop="longitude" width="120" show-overflow-tooltip/>
                        <el-table-column label="纬度" align="center" prop="latitude" width="120" show-overflow-tooltip/>
                        <el-table-column label="结构类型" align="center" prop="jglx" width="180" show-overflow-tooltip>
                            <template #default="scope">
                                <span v-if="scope.row.jglx=='0'">土木/石木结构</span>
                                <span v-if="scope.row.jglx=='1'">砌体结构</span>
                                <span v-if="scope.row.jglx=='2'">木结构</span>
                                <span v-if="scope.row.jglx=='3'">窑洞</span>
                                <span v-if="scope.row.jglx=='4'">钢筋混凝土结构</span>
                                <span v-if="scope.row.jglx=='5'">木（竹）结构</span>
                                <span v-if="scope.row.jglx=='6'">混杂结构</span>
                                <span v-if="scope.row.jglx=='7'">钢结构</span>
                                <span v-if="scope.row.jglx=='8'">其他结构</span>
                                <span v-if="scope.row.jglx=='9'">底部框架-抗震墙砌体结构</span>
                            </template> 
                        </el-table-column>
                        <el-table-column label="建成时间" align="center" prop="buildTime" width="160"/>
                        <el-table-column label="设防烈度" align="center" prop="mqsfld" width="100"/>
                        <el-table-column label="评估结果" align="center" prop="maxDestoryType" width="100">
                            <template #default="scope">
                                <span v-if="scope.row.maxDestoryType=='0'">基本破坏</span>

                                <span v-if="scope.row.maxDestoryType=='1'">轻微破坏</span>
                                <span v-if="scope.row.maxDestoryType=='2'">中等破坏</span>
                                <span v-if="scope.row.maxDestoryType=='3'">严重破坏</span>
                                <span v-if="scope.row.maxDestoryType=='4'">毁坏</span>
                            </template> 
                        </el-table-column>
                    </el-table>
                    <pagination v-show="total1 > 0" :total="total1" v-model:page="formData1.page" v-model:limit="formData1.rows"
                    @pagination="getResultAnalysis" />
                </div>
                <el-divider direction="vertical" border-style="dashed"></el-divider>
                <div class="rightBox">
                    <div>
                        <h2 style="text-align: center;">
                            <p>对于存在严重破坏和毁坏风险</p>
                            <p>的隐患房屋建议</p>
                        </h2>
                        <p>1）优先对重点地区和重点关注的房屋建筑，尽快开展的详细的抗震性能鉴定；</p>
                        <p>2）对于抗震性能鉴定不达标的房屋建筑，尽快制定抗震加固改造方案，分阶段推进加固改造，消减地震灾害风险隐患。</p>
                    </div>
                </div>
            </div>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="handleExport">房屋数据导出</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
  </div>
</template>

<script setup name="houseMap">
//地图
import HouseMap from '@/map/assess/house/map.vue';
import { titleCheck } from "@/api/assess/house";
import { ElMessage, ElMessageBox } from 'element-plus'
import {resultLists,countSeismic,countSeismic1,houseDestory, saveResult,seismicAssess, destructionAssess, getPicReport, uploadHouse,analyzeList,resultAnalysis,statistics,showdata } from "@/api/assess/map/house"
import SelectVersion from "@/components/SelectVersion/index.vue"
import { getImport,getExtentByIaId } from "@/api/business/activities";
import { getProvince, getChildArea } from "@/api/system/division";
import Chart from './chart.vue'
const baseUrl = import.meta.env.VITE_APP_BASE_API + "/attachment/downLoad?attachId=";
const route = useRoute();
const router = useRouter();
const { proxy } = getCurrentInstance();
const openAssess = ref(false);
const openParameter = ref(false);
const content = ref('房屋抗震能力评估');
const openExplain = ref(false);
const areaData = ref([]);
const cityData = ref([]);
const province = ref();
const provinceId = ref();
const city = ref();
const cityId = ref();
const counties = ref();
const countiesId = ref();
const value = ref([]);
const selectValue = ref([]);
const selectValueId = ref([]);
const openPic = ref(false);
const option1 = ref([]);;
const option2 = ref([]);
const steps = ref(1);
const type = ref(1);
const options1 = ref({});
const props1 = ref({ multiple: true});
const options = ref({});
const view = ref('手动选择');
const num = ref(0);
const props = ref({
     multiple: true,
     lazy: true, 
     lazyLoad(node, resolve) {
          const { level } = node
          if (level === 0) {  // 第一级加载省份
            getChildArea(node.data.value).then(res => {
              if (res.code === 200) {
                const nodes = res.data.map(item => {
                  return {
                    label: item.name,
                    value: item.id,
                    leaf: false
                  }
                })
                resolve(nodes)
              }
            })
          } else if(level === 1){  //  第二级加载城市
            getChildArea( node.data.value)
            .then(res => {
              if (res.code === 200) {
                const nodes = res.data.map(item => {
                  return {
                    label: item.name,
                    value: item.id,
                    leaf: false
                  }
                })
                resolve(nodes)
              }
            })
          }else{
            getChildArea( node.data.value)
            .then(res => {
              if (res.code === 200) {
                const nodes = res.data.map(item => {
                  return {
                    label: item.name,
                    value: item.id,
                    leaf: true
                  }
                })
                resolve(nodes)
              }
            })
          }
        }
    });
const titleName = (rule, value, callback) => {
    if (!value) {
        callback(new Error('请输入标题'))
    } else if (value) {
        const parmas = { sdaRelation: route.query.id, sdaAssFileTitel: value,sdaAssSeiIntensity:content.value }
        titleCheck(parmas).then(res => {
            if (!res.data) {
                callback()
            } else {
                callback(new Error("该标题已存在，请重新输入"))
            }
        }).catch(_ => {
            callback(new Error(_.message))
        })
    }
}
const data = reactive({
    queryParams: {
        lieDu: 'VI',
    },
    form: {},
    rules: {
        lieDu: [{ required: true }],
        czzzDataVersion: [{ required: true, message: "城镇住宅不能为空", trigger: "change" }],
        czfzzDataVersion: [{ required: true, message: "城镇非住宅不能为空", trigger: "change" }],
        nczzdlzzDataVersion: [{ required: true, message: "农村住宅(独立住宅)不能为空", trigger: "change" }],
        nczzjtzzDataVersion: [{ required: true, message: "农村住宅(集体住宅)不能为空", trigger: "change" }],
        ncfzzDataVersion: [{ required: true, message: "农村非住宅不能为空", trigger: "change" }],
        tjmb: [{ required: true, message: "图件模板不能为空", trigger: "change" }],
        ztdw: [{ required: true, message: "制图单位不能为空", trigger: "blur" }],
        title: [{ required: true, validator: titleName, trigger: "blur" }],
        tjbt: [{ required: true, message: "图件标题不能为空", trigger: "blur" }],
    }
})
const { queryParams, form, rules } = toRefs(data)

// 结果分析
const openAnalyze = ref(false);
const dataList = ref([]);
const dataList1 = ref([]);
const openSuggestion = ref(false);
const selectObj = ref({});
// 结果查看
const openView = ref(false);
const form1 = ref({})
const formData = ref({
    rows:10,
    page:1,
    id:route.query.id
})
const formData1 = ref({
    rows:10,
    page:1,
})
const numObj = ref({});
const total = ref(0);
const total1 = ref(0);
const loading = ref(false);
const loading1 = ref(false);
// 查看结果
const openResult = ref(false);
const radioResult = ref('');
const resultList = ref([])
function handleResult(){
    openAssess.value = false;
    openAnalyze.value = false;
    openResult.value = !openResult.value;
    radioResult.value = '';
}
function getResultList(result){
    resultLists({result,iaId:route.query.id}).then(res=>{
        resultList.value = res.data?res.data:[];
    }).catch(err=>{resultList.value=[]})
}
function radioResultChange(value){

    if(value=='0'||value=='1'){
        getResultList(value)
    }
}
// 下载
function handleExport1(id){
    proxy.download(`/assessplot/evaluationResults/exportExcel/${id}`, {}, `抗震能力结果.xls`)
}

function handleAnalyze(){
    openAnalyze.value = true;
    openAssess.value = false;
    openResult.value = false;
    radioResult.value = '';
    selectObj.value = {};
    getAnalyze();
}
function getAnalyze(){// 获取结果记录
    resultLists({result:'1',iaId:route.query.id}).then(res=>{
        dataList.value = res.data?res.data:[];
    }).catch(err=>{ dataList.value=[]})
}

function getResultAnalysis(){//评估结果分析
    resultAnalysis({...formData1.value,id:selectObj.value.id}).then(res=>{
        dataList1.value = res.data.rows?res.data.rows:[];
        total1.value = res.data.total;
        loading1.value = false;
        openSuggestion.value = true;
    }).catch(err=>{
        loading1.value = false;
    })
}
function handleShow(id){
    // showdata({id:id}).then(res=>{

    // })
}
function confirmAnalyze(){// 确认
    loading1.value = true;
    statistics({id:selectObj.value.id}).then(res=>{
        numObj.value = res.data;
        getResultAnalysis();
    })
}

/** 单选中数据 */
function handleCurrentChange(val) {
    console.log(val);
    selectObj.value = val;
};

// 房屋数据导出
function handleExport(rowId){
    let id='';
    if(openView.value){
       id = form1.value.attachId;
    }else if(openSuggestion.value){
        id=selectObj.value.id;
    }else if(radioResult.value){
        id=rowId;
    }
    proxy.download(`/data/resultAnalysis/exportExcel/${id}`, {}, `房屋数据评估结果.xls`)
}

function handleEdit (row) {// 修改
    router.push({
        path: '/assess/buildVulnerability',
        query:{...row,iaId:route.query.id},
    })
}

function handleAssess() {
    reset1();
    content.value = '房屋抗震能力评估';
    openResult.value = false;
    openAnalyze.value = false;
    openAssess.value = !openAssess.value;
    radioResult.value = '';
}
function changeRadio() {
    proxy.$refs['departmentTree'].$refs.panel.clearCheckedNodes()
    proxy.$refs['departmentTree'].$refs.panel.activePath = []
    reset1();
}

function departmentChange(){
    let node = proxy.$refs['departmentTree'].getCheckedNodes();
    let arr = [];
    let arr1 = [];
    node.forEach(item=>{
        if(item.pathLabels[2]){
            arr.push({province:item.pathLabels[0],city:item.pathLabels[1],prefecture:item.pathLabels[2]})
            arr1.push({provinceId:item.pathValues[0],cityId:item.pathValues[1],prefectureId:item.pathValues[2]})
        }
    })
    selectValue.value = arr;
    selectValueId.value = arr1;
}

function setParameter(nums) {
    num.value = nums;
    openAssess.value = false;
    openParameter.value = true;
    reset();
}
function reset() {
    proxy.resetForm("assessRef");
    // queryParams.value.tjmb = undefined;
    // queryParams.value.ztdw = undefined;
    // queryParams.value.tjbt = undefined;
    queryParams.value.czzzDataVersion = undefined;
    queryParams.value.czfzzDataVersion = undefined;
    queryParams.value.nczzdlzzDataVersion = undefined;
    queryParams.value.nczzjtzzDataVersion = undefined;
    queryParams.value.ncfzzDataVersion = undefined;
    queryParams.value.lieDu = 'VI'
}
function reset1() {
    selectValue.value = [];
    selectValueId.value = [];
}
function handleExplain() {
    openExplain.value = true;
};
function getSelecVersion(obj){
    queryParams.value[obj.name] = obj.code;
    proxy.$refs['assessRef'].clearValidate(obj.name)
}
// function toAssess() { // 评估
//     proxy.$refs["assessRef"].validate(valid => {
//         if (valid) {
//             proxy.$modal.loading("正在评估，请稍候...");
//             if (content.value == '房屋抗震能力评估') {
//                 seismicAssess({...queryParams.value,list:selectValue.value,iaId:route.query.id}).then(res => {
//                     finish(res);
//                 }).catch(()=>{
//                 })
//             } else {
//                 destructionAssess({...queryParams.value,list:selectValue.value,iaId:route.query.id}).then(res => {
//                     finish(res);
//                 }).catch(()=>{
//                 })
//             }

//         }
//     });
// }
function toAssess() { // 评估
    proxy.$refs["assessRef"].validate(valid => {
        if (valid) {
            proxy.$modal.loading("正在评估，请稍候...");
            let newAreaArr = [];
            selectValue.value.forEach(item=>{
                item.newArea = item.province+'-'+item.city+'-'+item.prefecture;
                newAreaArr.push(item.newArea);
            })
            if (content.value == '房屋抗震能力评估') {
                if(num.value==0){
                    countSeismic({...queryParams.value,list:selectValue.value,iaId:route.query.id,taskDistrict:newAreaArr.join('、')}).then(res => {
                        proxy.$modal.closeLoading();
                        console.log(res.data);
                        form1.value = {};
                        form1.value.list = res.data;
                        openView.value = true;
                        // finish(res);
                    }).catch(()=>{
                            proxy.$modal.closeLoading();
                    })
                }else{
                    countSeismic1({lieDu:queryParams.value.lieDu,iaId:route.query.id,taskDistrict:newAreaArr.join('、')}).then(res => {
                        proxy.$modal.closeLoading();
                        console.log(res.data);
                        form1.value = {};
                        form1.value.list = res.data;
                        openView.value = true;
                        // finish(res);
                    }).catch(()=>{
                        proxy.$modal.closeLoading();
                    })
                }
               
            } else {
                houseDestory({...queryParams.value,list:selectValue.value,iaId:route.query.id,taskDistrict:newAreaArr.join('、')}).then(res => {
                    proxy.$modal.closeLoading();
                    form1.value = {};
                    form1.value.attachId = res.data;
                    openView.value = true;
                    // finish(res);
                }).catch(()=>{
                })
            }

        }
    });
}
// 仅保存结果
function onlySave(){
    proxy.$modal.loading("正在保存，请稍候...");
    if(content.value=='房屋抗震能力评估'){
        saveResult({id:form1.value.list[0].resultAnalysis,iaId:route.query.id,result:'0'}).then(res=>{
            proxy.$modal.closeLoading();
            openView.value = false;
            openParameter.value = false;
            proxy.$modal.msgSuccess('保存成功');
        })
    }else{
        saveResult({id:form1.value.attachId,iaId:route.query.id,result:'1',}).then(res=>{
            proxy.$modal.closeLoading();
            openView.value = false;
            openParameter.value = false;
            proxy.$modal.msgSuccess('保存成功');
        })
    }

}
// 保存&出图
function savePic(){
    proxy.$refs["viewRef"].validate(valid => {
        if (valid) {
            proxy.$modal.loading("正在评估，请稍候...");
            if (content.value == '房屋抗震能力评估') {
                seismicAssess({...form1.value,list:form1.value.list,iaId:route.query.id,id:form1.value.list[0].resultAnalysis}).then(res => {
                    finish(res);
                }).catch(()=>{proxy.$modal.closeLoading();})
            } else {
                destructionAssess({...form1.value,iaId:route.query.id,id:form1.value.attachId,list:selectValue.value}).then(res => {
                    finish(res);
                }).catch(()=>{proxy.$modal.closeLoading();})
            }

        }
    });
}

function finish(res) {
    openParameter.value = false;
    proxy.$modal.closeLoading();
    ElMessageBox.alert('评估完成，查看结果！', '消息提示', {
        confirmButtonText: '确定',
        type: "success",
        callback: () => {
            openPic.value = true;
            proxy.resetForm("picRef");
            steps.value == 1;
            form.value = res.data;
        },
    })
}

function saves() {
    if (steps.value == 1) {
        openParameter.value = false;
        proxy.$refs["picRef"].validate(valid => {
            if (valid) {
                form.value.sdaAssFileId = form.value.attach.attachId;
                form.value.sdaAssSeiIntensity = form.value.count;
                form.value.sdaAssFileTitel = form.value.title;
                form.value.dataMessage = form.value.dataVersion;
                uploadHouse({ ...form.value, sdaRelation: route.query.id }).then(response => {
                    proxy.$modal.msgSuccess("上传成功");
                    openPic.value = false;
                    openView.value = false;
                }).catch(() => { });
            }
        });
    } else if (steps.value == 2) {
        openPic.value = false;
        openParameter.value = true;
    } else {
        openParameter.value = false;
        if (content.value == '房屋抗震能力评估') {
            proxy.$refs["picRef"].validate(valid => {
                if (valid) {
                    proxy.$modal.loading("正在评估，请稍候...");
                    seismicAssess({...queryParams.value,tjmb:form.value.tjmb,list:selectValue.value,iaId:route.query.id}).then(res => {
                        finish(res);
                    }).catch(()=>{
                })
                }
            });
        } else {
            proxy.$refs["picRef"].validate(valid => {
                if (valid) {
                    proxy.$modal.loading("正在评估，请稍候...");
                    destructionAssess({...queryParams.value,tjmb:form.value.tjmb,list:selectValue.value,iaId:route.query.id}).then(res => {
                        finish(res);
                    }).catch(()=>{
                })
                }
            });
        }
    }
}
function getCity() {
    getImport(route.query.id).then(res => {
        province.value = res.data.importantActivity.iaProvince;
        provinceId.value = res.data.importantActivity.provinceId;
        city.value = res.data.importantActivity.iaCity;
        cityId.value = res.data.importantActivity.cityId;
        counties.value = res.data.importantActivity.iaCounties;
        countiesId.value = res.data.importantActivity.countiesId;
        if(!city.value && ! counties.value ){
            type.value = 1;
            options.value = [{
                label: province.value,
                value: provinceId.value,
                leaf: false,
            }]
        }
        if ( counties.value ) {
            type.value = 2;
            options1.value = [{
                label: province.value,
                value: provinceId.value,
                leaf: false,
                children:[{
                    label: city.value,
                    value: cityId.value,
                    leaf: false,
                    children:[{
                        label: counties.value,
                        value: countiesId.value,
                        leaf: true
                    }]
                }]
            }]
        } 
        if( city.value && ! counties.value ) {
            type.value = 2;
            getChildArea(cityId.value).then(response => {
                areaData.value = response.data;
                areaData.value.forEach(item => {
                    item.value = item.id;
                    item.label = item.name;
                    item.leaf = true;
                });
                options1.value =  [{
                    label: province.value,
                    value: provinceId.value,
                    leaf: false,
                    children:[{
                        value: cityId.value,
                        label: city.value,
                        leaf: false,
                        children: areaData.value
                    }]
                }]
            });
            
        }
    })
}

function getType(num) {
    getPicReport(num).then(res => {
        if(num==10){
            option1.value =  res.data
        }else if(num==9){
            option2.value =  res.data
        }
    })
}

getType(10);
getType(9)
getCity();



//地图传参--start
const queryMapBool = ref(false);//是否开启地图圈选
//地图圈选结果参数
const queryMapDrawResult = ref({
  leftX:null,
  leftY:null,
  rightX:null,
  rightY:null,
  centerX:null,
  centerY:null,
});
//地图圈选
const queryMapClick = ()=>{
  queryMapBool.value = false;//关闭地图圈选
  //清空行政区划选择
  selectValue.value = [];
  selectValueId.value = [];
  nextTick(() => {
    queryMapBool.value = true;//开启地图圈选
  });
}
//关闭地图圈选
const clearQueryMapClick = ()=>{
  queryMapBool.value = false;//关闭地图圈选
  //清空地图圈选结果参数
  queryMapDrawResult.value = {
    leftX:null,
    leftY:null,
    rightX:null,
    rightY:null,
    centerX:null,
    centerY:null,
  }
}
//地图圈选结果
const showQueryMapDraw = (array)=>{
  console.log("地图圈选结果");
  console.log(array);
  let polygonWkt = array[0];
  let extent = array[1];
  let center = array[2];
  queryMapDrawResult.value = {
    leftX:extent[0],
    leftY:extent[1],
    rightX:extent[2],
    rightY:extent[3],
    centerX:center[0],
    centerY:center[1],
  }
}

//获取活动行政区划的范围
const mapExtent = ref([]);
function getMapExtentByIaId() {
  getExtentByIaId(route.query.id).then(res => {
    let data = res.data;
    console.log(data);
    //BOX(113.51660441700005 37.43676435400005,115.47735626200006 38.76359765400008)
    if(data.indexOf("BOX(")!=-1){
      //mapExtent.value = [113.51660441700005, 37.43676435400005,115.47735626200006, 38.76359765400008];
      let arr = data.split("BOX(")[1].split(")")[0].split(",");
      if(arr.length==2){
        let leftBottom = arr[0].split(" ");
        let rightTop = arr[1].split(" ");
        if(leftBottom.length==2 && rightTop.length==2){
          let left = Number(leftBottom[0]);
          let bottom = Number(leftBottom[1]);
          let right = Number(rightTop[0]);
          let top = Number(rightTop[1]);
          mapExtent.value = [left,bottom,right,top];
        }
      }
    }
  });
}
getMapExtentByIaId();
//地图传参--end
</script>

<style lang="scss" scoped>
:deep(.el-transfer__buttons) {
    padding: 0 10px;

    .el-transfer__button {
        margin: 15px 0;
        display: block;
    }

    .el-transfer__button:nth-child(2) {
        margin-left: 0px;
    }

    .el-button+.el-button {
        margin-left: 0px;
    }
}
.showResult{
    position: absolute;
    width: 200px;
    top: 72px;
    left: 106px;
    padding: 20px;
    background: rgba($color: #fff, $alpha: 0.7);//zyt修改
    border: 1px solid #000;
}
.showResultList{
    position: absolute;
    width: 500px;
    top: 72px;
    left: 306px;
    padding: 20px;
    background: rgba($color: #fff, $alpha: 0.7);//zyt修改
    border: 1px solid #000;
}
.showAssess {
    position: absolute;
    top: 20px;
    left: 107px;
    width: 536px;
    padding: 20px;
    background: rgba($color: #fff, $alpha: 0.7);//zyt修改
    border: 1px solid #000;

    p {
        font-weight: bold;
    }
}

.footer {
    text-align: center;
    margin-top: 20px;
}

.tab-title {
    font-size: 16px;
    font-weight: bold;
    border-left: 4px solid #0D9AFF;
    font-family: PingFangSC-Medium;
    padding-left: 10px;
    margin-bottom: 20px;
}

.indent {
    display: inline-block;
    text-indent: 2em;
}
.suggesBox{
    height: 865px;
    display: flex;
    .el-divider--vertical {
        display: inline-block;
        height: 100%;
        margin: 0 8px;
    }
    .leftBox{
       flex: 1; 
    }
    .rightBox{
        width:300px;
        min-height: 500px;
        display: flex;
        align-items: center;
        justify-content: center;
        div{
            >p{
                font-size: 16px;
                text-indent: 2em;
                padding:0 20px;
                line-height: 50px;
            }
        }
    }
}

:deep(.el-table){
    th{
        border-bottom: 1px solid #f5f9fe!important;
    }
}
:deep(.pagination-container){
    .el-pagination{
        left: 165px!important;
    }
}
</style>